
//天气初始化函数
function initWeather(){
	var myCity = new BMap.LocalCity();
	myCity.get(function(result){
		var cname = result.name;
		cname = cname.replace("市","");
		$.getJSON("weather_getWeatherCodeByName.do",{cityname:cname,level:"3"},function(json){
			if(json==null||json.weathercode==null){
				return;
			}
			
			var wurl = "http://m.weather.com.cn/data/"+json.weathercode+".html";
			$.get("../../http_getContent.do",{url:wurl},function(json){
				var jsonObj = jQuery.parseJSON(json);
				var cityname = jsonObj.weatherinfo.city;
				var date = jsonObj.weatherinfo.date_y;
				var week = jsonObj.weatherinfo.week;
				var temp1 = jsonObj.weatherinfo.temp1.replace("~","/");
				var weather1 = jsonObj.weatherinfo.weather1;
				var wind1 = jsonObj.weatherinfo.wind1;

				var temp2 = jsonObj.weatherinfo.temp2.replace("~","/");
				var weather2 = jsonObj.weatherinfo.weather2;
				var wind2 = jsonObj.weatherinfo.wind2;

				var temp3 = jsonObj.weatherinfo.temp3.replace("~","/");
				var weather3 = jsonObj.weatherinfo.weather3;
				var wind3 = jsonObj.weatherinfo.wind3;

				var temp4 = jsonObj.weatherinfo.temp4.replace("~","/");
				var weather4 = jsonObj.weatherinfo.weather4;
				var wind4 = jsonObj.weatherinfo.wind4;

				var temp5 = jsonObj.weatherinfo.temp5.replace("~","/");
				var weather5 = jsonObj.weatherinfo.weather5;
				var wind5 = jsonObj.weatherinfo.wind5;


				var temp6 = jsonObj.weatherinfo.temp6.replace("~","/");
				var weather6 = jsonObj.weatherinfo.weather6;
				var wind6 = jsonObj.weatherinfo.wind6;


				

				var index_d = jsonObj.weatherinfo.index_d;

				
				var index_uv = jsonObj.weatherinfo.index_uv;

				$("#cityname").html(cityname);
				$("#datetime").html(getDateStr(0));
				$("#datetime2").html(getDateStr(1).substring(5));
				$("#datetime3").html(getDateStr(2).substring(5));
				$("#datetime4").html(getDateStr(3).substring(5));
				$("#datetime5").html(getDateStr(4).substring(5));
				$("#datetime6").html(getDateStr(5).substring(5));

				$("#temp1").html(temp1);
				$("#weather1").html(weather1);
				$("#wind1").html(wind1);
				$("#index_uv").html(index_uv);
				

				$("#temp2").html(temp2);
				$("#weather2").html(weather2);
				$("#wind2").html(wind2);

				$("#temp3").html(temp3);
				$("#weather3").html(weather3);
				$("#wind3").html(wind3);

				$("#temp4").html(temp4);
				$("#weather4").html(weather4);
				$("#wind4").html(wind4);

				$("#temp5").html(temp5);
				$("#weather5").html(weather5);
				$("#wind5").html(wind5);

				$("#temp6").html(temp6);
				$("#weather6").html(weather6);
				$("#wind6").html(wind6);
				
				$("#weatherImg1").attr("title",index_d);
				var imgPath1 = getWeatherImagePath(weather1);
				$("#weatherImg1").attr("src","../../"+imgPath1);

				var imgPath2 = getWeatherImagePath(weather2,true);
				$("#weatherImg2").attr("src","../../"+imgPath2);

				var imgPath3 = getWeatherImagePath(weather3,true);
				$("#weatherImg3").attr("src","../../"+imgPath3);

				var imgPath4 = getWeatherImagePath(weather4,true);
				$("#weatherImg4").attr("src","../../"+imgPath4);

				var imgPath5 = getWeatherImagePath(weather5,true);
				$("#weatherImg5").attr("src","../../"+imgPath5);

				var imgPath6 = getWeatherImagePath(weather6,true);
				$("#weatherImg6").attr("src","../../"+imgPath6);

			});
		});
		
	});
	return;
	var ipurl = "http://61.4.185.48:81/g/";
	$.get("../../http_getContent.do",{url:ipurl},function(data){
		var cityid = data.split(';')[1].split('=')[1];
		
		


	});
}


function initCoverWeather(citynameId,weatherImg1Id,temp1Id,weather1Id){
	var myCity = new BMap.LocalCity();
	myCity.get(function(result){
		var cname = result.name;
		cname = cname.replace("市","");
		$.getJSON("weather_getWeatherCodeByName.do",{cityname:cname,level:"3"},function(json){
			if(json==null||json.weathercode==null){
				return;
			}
			var wurl = "http://m.weather.com.cn/data/"+json.weathercode+".html";
			$.get("http_getContent.do",{url:wurl},function(json){
				var jsonObj = jQuery.parseJSON(json);
				var cityname = jsonObj.weatherinfo.city;
				var date = jsonObj.weatherinfo.date_y;
				var week = jsonObj.weatherinfo.week;
				var temp1 = jsonObj.weatherinfo.temp1.replace("~","/");
				var weather1 = jsonObj.weatherinfo.weather1;
				var wind1 = jsonObj.weatherinfo.wind1;
				var index_d = jsonObj.weatherinfo.index_d;
				var img_title1 = jsonObj.weatherinfo.img_title1;
				



				$("#"+temp1Id).html(temp1);
				$("#"+citynameId).html(cityname);
				$("#"+weather1Id).html(weather1);

				$("#"+weatherImg1Id).attr("title",index_d);
				var imgPath1 = getWeatherImagePath(weather1);
				$("#"+weatherImg1Id).attr("src",imgPath1);
				

			});
			
		});
	});
	
	
}

function getWeatherImagePath(img_title1,showDif){
	var imgPath;
	if(showDif == null||showDif==""){
		showDif = false;
	}
	if(img_title1.split("转")[0].indexOf("多云")!=-1){
		if(isDay()||showDif){
			imgPath = "image/weather-icon/weather-icon-21.png";
		}else{
			imgPath = "image/weather-icon/weather-icon-20.png";
		}
		return imgPath;
	}else if(img_title1.split("转")[0].indexOf("晴")!=-1){
		if(isDay()||showDif){
			imgPath = "image/weather-icon/weather-icon-26.png";
		}else{
			imgPath = "image/weather-icon/weather-icon-25.png";
		}
		return imgPath;
	}
	else if(img_title1.split("转")[0].indexOf("雾")!=-1){
		if(isDay()||showDif){
			imgPath = "image/weather-icon/weather-icon-15.png";
		}else{
			imgPath = "image/weather-icon/weather-icon-14.png";
		}
		return imgPath;
	}
	else if(img_title1.split("转")[0].indexOf("雨夹雪")!=-1){
		if(isDay()||showDif){
			imgPath = "image/weather-icon/weather-icon-44.png";
		}else{
			imgPath = "image/weather-icon/weather-icon-44.png";
		}
		return imgPath;
	}
	else if(img_title1.split("转")[0].indexOf("雨")!=-1){
		if(isDay()||showDif){
			imgPath = "image/weather-icon/weather-icon-04.png";
		}else{
			imgPath = "image/weather-icon/weather-icon-40.png";
		}
		return imgPath;
	}
	else if(img_title1.split("转")[0].indexOf("雪")!=-1){
		if(isDay()||showDif){
			imgPath = "image/weather-icon/weather-icon-08.png";
		}else{
			imgPath = "image/weather-icon/weather-icon-41.png";
		}
		return imgPath;
	}
	else if(img_title1.split("转")[0].indexOf("阴")!=-1){
		if(isDay()||showDif){
			imgPath = "image/weather-icon/weather-icon-19.png";
		}else{
			imgPath = "image/weather-icon/weather-icon-19.png";
		}
		return imgPath;
	}
	//return imgPath;

}
//返回true是白天
function isDay(){
	var time = new Date();
	var hours = time.getHours(); //获取时间的小时
	
	if (hours>=17 || hours <=7){ 
		return false;
	}
	else{
		return true;
	}
	 
}

function getDateStr(AddDayCount) {
    var myDate = new Date();
    myDate.setDate(myDate.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var year = myDate.getFullYear(); 
	var month = myDate.getMonth()+1; 
	var day = myDate.getDate(); 
	var week = myDate.getDay();
	var weekstr = "";
	

	switch (week){
		case 0:
			weekstr="日";
			break;
		case 1:
			weekstr="一";
			break;
		case 2:
			weekstr="二";
			break;
		case 3:
			weekstr="三";
			break;
		case 4:
			weekstr="四";
			break;
		case 5:
			weekstr="五";
			break;
		case 6:
			weekstr="六";
			break;
		default:
			break;   
			
	}
	var rlt = year+"年"+month+"月"+day+"日&nbsp;&nbsp;星期"+weekstr;
	return rlt;
}
